home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / kriegspi / review.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-30  |  2.1 KB  |  108 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: review.c,v 1.4 87/05/19 18:45:56 schoch Exp $";
  3. #endif
  4.  
  5. #include "externs.h"
  6. #include <sys/time.h>
  7. #define STEPTIME 3    /* time between moves in seconds */
  8.  
  9. /*
  10.  * Show a review of the game, with all pieces showing.  I assume this doesn't
  11.  * get called when we're playing.
  12.  */
  13. review ()
  14. {
  15.     int color = WHITE;
  16.     MOVELIST m;
  17.     auto int fds;
  18.     struct timeval tv;
  19.  
  20.     if (state == REVIEW) {
  21.         message("Already showing review\n", MESSAGE);
  22.         return;
  23.     }
  24.     state = REVIEW;
  25.     initdirlists ();
  26.     initpiecelocs ();
  27.     initboard (TRUE);
  28. #ifndef XKS
  29.     touchwin (stdscr);
  30. #endif
  31.     redraw ();
  32.     m = movelist;
  33.     while (m) {
  34.         if (state != REVIEW)        /* somebody stopped us. */
  35.             return;
  36. #ifdef XKS
  37.         fds = 1 << dpyno();
  38. #else
  39.         fds = 1;    /* stdin */
  40. #endif
  41.         tv.tv_usec = 0;
  42.         tv.tv_sec = STEPTIME;
  43.         (void) select(32, &fds, 0, 0, &tv);
  44. #ifdef XKS
  45.         if (fds & (1<<dpyno())) {
  46.             handle_input();
  47.             if (state != REVIEW)
  48.                 return;
  49.             while (XPending()) {
  50.                 handle_input();
  51.                     if (state != REVIEW)
  52.                         return;
  53.             }
  54.             continue;
  55.         }
  56. #else
  57.         if (fds & 1) {
  58.             if (getchar() == '\f')    /* control-L */
  59.                 redraw();
  60.             continue;
  61.         }
  62. #endif
  63.         if (occupant[m->from] == KING &&
  64.             ((m->to - m->from) == 2 ||
  65.             (m->from - m->to) == 2)) {    /* castling */
  66.             makereviewmove (m -> from, m -> to, color);
  67.             m = m->n;
  68.         }
  69.         makereviewmove (m -> from, m -> to, color);
  70.         refresh();
  71.         m = m -> n;
  72.         color = 1 - color;
  73.     }
  74.     state = OVER;
  75. }
  76.  
  77. makereviewmove (from, to, color)
  78.     int from, to, color;
  79. {
  80.     int victim;
  81.     char buf[128];
  82.  
  83.     mclear(INPUT);
  84.     if (victim = findvictim (from, to)) {
  85.         display_capture(whose[victim], occupant[victim]);
  86.         whose [victim] = EMPTY;
  87.         occupant[victim] = 0;
  88.         redraw_pos(victim);
  89.     }
  90.     whose [to] = color;
  91.     occupant [to] = occupant [from];
  92.     whose [from] = EMPTY;
  93.     occupant [from] = 0;
  94.     if (occupant [to] == PAWN
  95.     && ((to / 10 == 1 && color == WHITE)
  96.     ||  (to / 10 == 8 && color == BLACK)))
  97.         occupant [to] = QUEEN;
  98.     redraw_pos(from);
  99.     redraw_piece(to);
  100.     if (reverse) {
  101.         from = 99 - from;
  102.         to = 99 - to;
  103.     }
  104.     sprintf(buf, ": %1c%1d-%1c%1d", 'a' + (9-from%10)-1, (9-from/10),
  105.                     'a' + (9 - to%10)-1, (9 - to/10));
  106.     message(buf, INPUT);
  107. }
  108.